package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.Util.FileUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * projectName: gmall
 *
 * @author: 陈鹏
 * time: 2022/9/22 15:38 星期四
 * description: 文件管理
 */
@RestController
@RequestMapping(value = "/admin/product")
public class FileController {

    @Value("${fileServer.url}")
    private String fileUrl;

    /**
     * 文件上传
     * @param file
     * @return
     */
    @PostMapping(value = "/fileUpload")
    public Result fileLoad(@RequestParam MultipartFile file){

        String path = FileUtil.fileUpload(file);
        if(path == null){
            return Result.fail();
        }
        return Result.ok(fileUrl+path);
    }
}
